﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CopyDataObject.cs" company="">
//   
// </copyright>
// <summary>
//   The copy data object.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Libium.WindowsForms.Controls
{
    using System;
    using System.Linq;
    using System.Windows.Forms;

    using Libium.Core;

    /// <summary>
    /// The copy data object.
    /// </summary>
    public class CopyDataObject : IDataObject
    {
        #region Fields

        /// <summary>
        /// The _data.
        /// </summary>
        private readonly ICopyData _data;

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="CopyDataObject"/> class.
        /// </summary>
        /// <param name="data">
        /// The data.
        /// </param>
        public CopyDataObject(ICopyData data)
        {
            _data = data;
        }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The get data.
        /// </summary>
        /// <param name="format">
        /// The format.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        public object GetData(Type format)
        {
            return GetData(format.FullName);
        }

        /// <summary>
        /// The get data.
        /// </summary>
        /// <param name="format">
        /// The format.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        public object GetData(string format)
        {
            return _data.GetValue<object>(format);
        }

        /// <summary>
        /// The get data.
        /// </summary>
        /// <param name="format">
        /// The format.
        /// </param>
        /// <param name="autoConvert">
        /// The auto convert.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        public object GetData(string format, bool autoConvert)
        {
            return GetData(format);
        }

        /// <summary>
        /// The get data present.
        /// </summary>
        /// <param name="format">
        /// The format.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool GetDataPresent(Type format)
        {
            return GetDataPresent(format.FullName);
        }

        /// <summary>
        /// The get data present.
        /// </summary>
        /// <param name="format">
        /// The format.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool GetDataPresent(string format)
        {
            return _data.IsExist(format);
        }

        /// <summary>
        /// The get data present.
        /// </summary>
        /// <param name="format">
        /// The format.
        /// </param>
        /// <param name="autoConvert">
        /// The auto convert.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool GetDataPresent(string format, bool autoConvert)
        {
            return GetDataPresent(format);
        }

        /// <summary>
        /// The get formats.
        /// </summary>
        /// <returns>
        /// The <see cref="string[]"/>.
        /// </returns>
        public string[] GetFormats()
        {
            return _data.Formats.ToArray();
        }

        /// <summary>
        /// The get formats.
        /// </summary>
        /// <param name="autoConvert">
        /// The auto convert.
        /// </param>
        /// <returns>
        /// The <see cref="string[]"/>.
        /// </returns>
        public string[] GetFormats(bool autoConvert)
        {
            return GetFormats();
        }

        /// <summary>
        /// The set data.
        /// </summary>
        /// <param name="data">
        /// The data.
        /// </param>
        public void SetData(object data)
        {
            SetData(data.GetType().FullName, data);
        }

        /// <summary>
        /// The set data.
        /// </summary>
        /// <param name="format">
        /// The format.
        /// </param>
        /// <param name="data">
        /// The data.
        /// </param>
        public void SetData(Type format, object data)
        {
            SetData(format.FullName, data);
        }

        /// <summary>
        /// The set data.
        /// </summary>
        /// <param name="format">
        /// The format.
        /// </param>
        /// <param name="data">
        /// The data.
        /// </param>
        public void SetData(string format, object data)
        {
            _data.SetValue(format, data);
        }

        /// <summary>
        /// The set data.
        /// </summary>
        /// <param name="format">
        /// The format.
        /// </param>
        /// <param name="autoConvert">
        /// The auto convert.
        /// </param>
        /// <param name="data">
        /// The data.
        /// </param>
        public void SetData(string format, bool autoConvert, object data)
        {
            SetData(format, data);
        }

        #endregion
    }
}